package org.dejavu.design.singleton;

import java.util.Vector;

/**
* <p>Title: SingletonTest</p>
* <p>Description: </p>
* <p>Company: </p> 
* @author dejavu
* @date 2016-9-7 下午4:09:58
*/
public class SingletonTest {

	private static SingletonTest instance = null;
	private Vector properties = null;

	public Vector getProperties() {
		return properties;
	}
	
	/**
	 * 
	 */
	private SingletonTest() {
		System.out.println("create "+this.toString());
	}

	/**
	 * 第二种加载方式
	 */
	private static synchronized void syncInit() {
		System.out.println("private static synchronized void syncInit()");
		if (instance == null) {
			System.out.println("before new SingletonTest");
			instance = new SingletonTest();
			System.out.println("after new SingletonTest");
		}
	}

	public static SingletonTest getInstance() {
		System.out.println("public static SingletonTest getInstance()");
		if (instance == null) {
			syncInit();
		}
		System.out.println("return public static SingletonTest getInstance()");
		return instance;
	}
	
	public void updateProperties() {
		SingletonTest shadow = new SingletonTest();
		properties = shadow.getProperties();
	}
	
}
